package com.example.demo.service.Impl;


import com.example.demo.ao.SysUser;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class UserServiceImpl implements UserService {
    /**
     * 盐值，混淆密码
     */
    public static final String SALT = "omcs";

    @Autowired
    private UserMapper userMapper;



    /**
     * 获取登录用户
     *
     * @param request
     * @return
     */
    public SysUser getLoginUser(HttpServletRequest request) {
        // 判断是否登录
        Object userObj = request.getSession().getAttribute("1");
        SysUser currentUser = (SysUser) userObj;
        if (currentUser == null || currentUser.getUserId() == null) {
            return null;
        }
        // 查数据库
        long userId = currentUser.getUserId();
        currentUser = userMapper.getUserById(userId);
        if (currentUser == null) {
            return null;
        }
        return currentUser;
    }


}
